package com.jml.activitymq.整合springboot.producer;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class Producer {

	@Autowired
	//private JmsMessagingTemplate jmsMessagingTemplate;
	private JmsTemplate jmsMessagingTemplate;

	//两个配置文件二选1都可以

	@Autowired
	private Queue queue;

	//表示每隔三秒发送消息
	@Scheduled(fixedDelay = 3000)
	public void send() throws JMSException {
		String msg = System.currentTimeMillis()+"--测试消息！";
		/*ConnectionFactory connectionFactory = jmsMessagingTemplate.getConnectionFactory();
		Connection connection = connectionFactory.createConnection();
		Session session = connection.createSession(Boolean.FALSE, Session.CLIENT_ACKNOWLEDGE);
		TextMessage textMessage = session.createTextMessage(msg);*/
		jmsMessagingTemplate.convertAndSend(queue,msg);
		int sessionAcknowledgeMode = jmsMessagingTemplate.getSessionAcknowledgeMode();

		System.out.println(msg);
	}


}
